<?
if (!defined('IN_RJ')) die("Error 404");
if($cmd[1]=="video"){
if((!is_numeric($cmd[3])) && !$cmd[3]) $cmd[3]=1;
$doc = new DOMDocument( "1.0", 'UTF-8' );
$doc->formatOutput = true;
$file_xml='source/autopro.xml';
@$doc->load($file_xml);
  $keys = $doc->getElementsByTagName( "key" );
  $total=0;
foreach( $keys as $ro_key ){
$total++;
}
$list_video_title=$lang['funny_clip'];
$list_video_title_ascii=$func->utf8_to_ascii($lang['funny_clip']);
	if($total){
		$video_per_page = 18;
		if($total%$video_per_page!=0)
		$pages = intval($total/$video_per_page)+1;
		else $pages = intval($total/$video_per_page);
		
			$ro=$tpl->get_tpl("list_video");
			$t['row'] = $tpl->get_block_from_str($ro,'list_video.row',1);
			$html='';
		 $count_video=0;
		   foreach( $keys as $key )
		  {
		  	  $stts = $key->getElementsByTagName( "stt" );
			  $stt = $stts->item(0)->nodeValue;
			  if($stt>(($cmd[3]-1)*$video_per_page)){
				  $ids = $key->getElementsByTagName( "id" );
				  $id = $ids->item(0)->nodeValue;
				  $names = $key->getElementsByTagName( "name" );
				  $name = $names->item(0)->nodeValue;
				  $locations = $key->getElementsByTagName( "location" );
				  $location = $locations->item(0)->nodeValue;
				  $images = $key->getElementsByTagName( "image" );
				  $image = $images->item(0)->nodeValue;
				  $name_acsii=$func->utf8_to_ascii($func->title_2_ascii($name));
						$tr= (fmod($count_video,3) == 0)?'</tr><tr>':'';
						$count_video++;
						$html.=$tpl->assign_vars($t['row'],array(
								'video.NAME'	=> $name,
								'video.IMG'		=> $image,
								'video.URL'		=> $func->change_link("video-detail",$id,$func->title_2_ascii(urldecode($name),true)),
								'video.TR'		=> $tr,
								'video.ID'		=> $id,
							)
						);
					if($count_video>=$video_per_page)
					break;
			   }
         } // Het for
		$ro=$tpl->assign_vars($ro,array(
				'video.TOTAL'	=> "{$lang['total']} <b>{$total}</b> video</b>",
				'video.PAGES'	=> $func->viewpages($total,$video_per_page,$cmd[3],$func->title_2_ascii($list_video_title_ascii)),	
			)
		);
		$ro=$tpl->assign_blocks_content($ro,array(
				'list_video'	=> $html,
			)
		);
		
	}
	else $ro=box_announcement($lang['no_data']);
		$main_content=$ro;
		$title_web_bar=$list_video_title;
		$title_ascii_web_bar=$list_video_title_ascii;
}
if($cmd[1]=="video-detail" && is_numeric($cmd[2])){
$doc = new DOMDocument( "1.0", 'UTF-8' );
$doc->formatOutput = true;
$file_xml='source/autopro.xml';
@$doc->load($file_xml);
$video_id=$cmd[2];
  $keys = $doc->getElementsByTagName( "key" );

		   foreach( $keys as $key )
		  {
		  	  $ids = $key->getElementsByTagName( "id" );
			  $id = $ids->item(0)->nodeValue;
			  $names = $key->getElementsByTagName( "name" );
			  $name = $names->item(0)->nodeValue;
			  $locations = $key->getElementsByTagName( "location" );
			  $location = $locations->item(0)->nodeValue;
			  $images = $key->getElementsByTagName( "image" );
			  $image = $images->item(0)->nodeValue;
			 
			  if($video_id==$id){
			  $url_flv=$location;
			  $video_title=$name;
			  $video_img=$image;
			  break;
			  }
			  
		}
		if($url_flv && $video_title){
			$ro=$tpl->get_tpl("play_video");	
			 $video_title_ascii=$func->utf8_to_ascii($video_title);
			 $qr=$DB->query("select * from {$conf['prefix']}player where player_name='flv'");
			 $ro1=$DB->fetch_row($qr);
			 preg_match('@^(?:http://)?([^/]+)@i',$video_img, $local);
			 $link_direct="http://".$local[1].$url_flv;
			 $player=$func->unhtmlchars($ro1['player_html']);
			 $player=str_replace("{WIDTH}",$ro1['player_width'],$player);
			 $player=str_replace("{HEIGHT}",$ro1['player_height'],$player);
			 $player=str_replace("{URL}",$link_direct,$player);
			$ro=$tpl->assign_vars($ro,array(
					'video.TITLE'	=> $video_title,
					'video.PLAYER'	=> $player,
					'video.URL_DOWNLOAD'	=> $link_direct,
			 	)
			);
        }
		else{
			$ro=box_announcement($lang['no_data']);
			$video_title=$lang['no_data'];
			$video_title_ascii=$func->utf8_to_ascii($lang['no_data']);
		}
		$main_content=$ro;
		$title_web_bar=$video_title;
		$title_ascii_web_bar=$video_title_ascii;

}
?>

